﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using SDK10kWrapper;

namespace TestUI
{
    public partial class Camera4Test : Form
    {
        Camera cam1, cam2, cam3, cam4;

        public Camera4Test()
        {
            InitializeComponent();
        }

        private void CameraTest_Load(object sender, EventArgs e)
        {
            cam1 = new Camera(panel1, "194.36.79.201", "D:\\cam1.avi");
            cam2 = new Camera(panel2, "194.36.79.202", "D:\\cam2.avi");
            cam3 = new Camera(panel3, "194.36.79.203", "D:\\cam3.avi");
            cam4 = new Camera(panel4, "194.36.79.204", "D:\\cam4.avi");
            
            List<Camera> fails;
            if (Camera.ConnectAll(out fails)) label1.Text = "All Cameras is Connected.";
            else
            {
                string s_fail = "";
                foreach (Camera failcam in fails)
                {
                    s_fail += ", " + failcam.Name;
                }

                label1.Text = ("Can not connect to All Camera" + s_fail + " Fail !");
            }

            Camera.PlayAll(); // Call to Static Method of Class will play all instance at the same time.
        }

        private void butRecord_Click(object sender, EventArgs e)
        {
            Camera.StartRecordAll();
        }

        private void butStop_Click(object sender, EventArgs e)
        {
            Camera.StopRecordAll();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (cam1.IsPlaying) cam1.Pause();
            else cam1.Play();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Camera.PlayAll();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Camera.PauseAll();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Camera.StopAll();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            using (Camera cam = new Camera(null))
            {

            }

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            label4.Text = Camera.Count.ToString();
        }

        private void Camera4Test_FormClosed(object sender, FormClosedEventArgs e)
        {
            Camera.DisposeAll();
        }
    }
}